package lee.vioson.ebook.ui.components.dialog

import androidx.compose.foundation.clickable
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material3.AlertDialog
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import lee.vioson.ebook.R
import lee.vioson.ebook.ui.AppTheme

/**
 *Author:viosonlee
 *Date:2023/6/17
 *DESCRIPTION:
 */

val dialogButtonTextStyle: TextStyle
    @Composable
    get() = TextStyle(
        fontSize = 14.sp,
        color = AppTheme.appColors.grayTextColor,
        fontWeight = FontWeight.Medium
    )
val dialogContentTextStyle: TextStyle
    @Composable
    get() = TextStyle(
        fontSize = 14.sp,
        color = AppTheme.appColors.grayTextColor,
        fontWeight = FontWeight.Medium
    )
val dialogTitleTextStyle: TextStyle
    @Composable
    get() = TextStyle(
        fontSize = 18.sp,
        color = AppTheme.appColors.grayTextColor,
        fontWeight = FontWeight.Medium
    )

@Composable
fun AlertDialog(
    show: Boolean,
    title: String,
    content: String,
    confirm: String? = null,
    dismiss: String? = null,
    onDismissRequest: () -> Unit,
    onConfirmRequest: () -> Unit
) {
    if (show)
        AlertDialog(
            onDismissRequest = onDismissRequest,
            confirmButton = {
                Text(
                    text = confirm ?: stringResource(id = R.string.dialog_YES),
                    style = dialogButtonTextStyle,
                    modifier = Modifier.clickable { onConfirmRequest() }
                )
            },
            dismissButton = {
                Text(
                    text = dismiss ?: stringResource(id = R.string.dialog_NO),
                    style = dialogButtonTextStyle,
                    modifier = Modifier.clickable { onDismissRequest() }
                )
            },
            title = {
                Text(
                    text = title,
                    style = dialogTitleTextStyle
                )
            },
            text = {
                Text(
                    text = content,
                    style = dialogContentTextStyle
                )
            },
            shape = RoundedCornerShape(4.dp)
        )
}